package com.muy.redis.common.tree.actions;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ReadAction;
import com.intellij.util.concurrency.NonUrgentExecutor;
import com.muy.redis.common.dialog.MrRedisConnectionSettingsDialog;
import com.muy.redis.common.tree.MTTreeCell;
import com.muy.redis.common.tree.TreeCellEventExeContext;
import com.muy.redis.common.tree.TreeCellEventHandle;
import com.muy.redis.common.tree.TreePanelMark;
import com.muy.redis.utils.JTreeUtils;
import com.muy.redis.view.component.MrRedisEditorJpanelLeft;
import com.muy.redis.view.window.redis.MrRedisTree;
import com.muy.redis.view.window.redis.tree.MTTreeCellMrRedisKey;
import com.muy.redis.view.window.redis.tree.MTTreeCellMrRedisTopDb;

import javax.swing.tree.DefaultMutableTreeNode;
import java.util.concurrent.CompletableFuture;

/**
 * @Author jiyanghuang
 * @Date 2023/9/28 22:40
 */
public class MrRedisEditConnectionParamAction extends AbstractMTTreeCellSelectTreeAction{

    private TreePanelMark treePanelMark;

    public MrRedisEditConnectionParamAction(TreePanelMark treePanelMark) {
        super("Edit", "Edit", AllIcons.Actions.Edit, treePanelMark);
        this.treePanelMark = treePanelMark;
    }

    public MrRedisEditConnectionParamAction(TreePanelMark treePanelMark, String title, String desc) {
        super(title, desc, AllIcons.Actions.Edit, treePanelMark);
    }

    @Override
    public void handleSelectTree(DefaultMutableTreeNode mutableTreeNode, MTTreeCell mtTreeCell) {
        MrRedisTree mrRedisTree = (MrRedisTree)treePanelMark;
        if(mtTreeCell instanceof MTTreeCellMrRedisTopDb){
            MTTreeCellMrRedisTopDb mtTreeCellMrRedisTopDb = (MTTreeCellMrRedisTopDb)mtTreeCell;
            new MrRedisConnectionSettingsDialog(mrRedisTree.getProject(), mtTreeCellMrRedisTopDb.getMrRedisConnectionParam(), mrRedisTree).ofDialogShow();
        }

    }
}
